<template>
  <div style="padding: 20px" class="main">
    <div class="aboutusTitle">
      <i class="el-icon-s-home"></i>
      地产详情
    </div>
    <div class="propertyDetail">
      <div class="title">
        {{ propertyDetail.title }}
        <el-tag
          type="success"
          v-for="(item, index) in propertyDetail.tags"
          :key="index"
          style="margin: 0 5px"
          >{{ item }}</el-tag
        >
      </div>
      <div class="map">
        <div class="left">
          <img v-fixImg="require('@/assets/no.png')" :src="imgSrc" alt="" />
        </div>
        <div class="right">
          <div class="up">
            <div class="showPhoto">
              <div
                class="little"
                v-for="(item, index) in propertyDetail.photos"
                :key="index"
                @click="imgSrc = item"
              >
                <img v-fixImg="require('@/assets/no.png')" :src="item" alt="" />
              </div>
            </div>
            <div class="price">
              <span
                >价格：
                <i
                  v-text="
                    Boolean(Number(propertyDetail.price)) ||
                    propertyDetail.price == 0
                      ? propertyDetail.price
                      : '???'
                  "
                  style="color: red; padding: 0 5px; font-size: 25px"
                >
                  {{ propertyDetail.price }} </i
                >元/平方</span
              >
            </div>
          </div>
          <div class="down">
            <MapContainer ref="map"></MapContainer>
            <p style="padding: 10px 0">地址：{{ address }}</p>
          </div>
        </div>
      </div>
      <div class="content" v-html="propertyDetail.content"></div>
    </div>
  </div>
</template>

<script>
import { getPropertyById } from "@/api";
import MapContainer from "../components/MapContainer.vue";
export default {
  components: { MapContainer },
  data() {
    return {
      propertyDetail: {},
      imgSrc: "#",
      address: "",
    };
  },
  created() {
    this.getPropertyById();
  },
  methods: {
    async getPropertyById() {
      const { data } = await getPropertyById(
        this.$route.query.propertyDetailId
      );
      this.propertyDetail = data;
      this.imgSrc = this.propertyDetail.photos[0];
      this.address = this.propertyDetail.address.replace(/,/g, "");
      this.$refs.map.getAddress(this.address);
    },
  },
};
</script>

<style lang="less" scoped>
.propertyDetail {
  border: 1px solid #ccc;
  padding: 10px;
  .title {
    vertical-align: middle;
    line-height: 32px;
    padding: 20px 45px;
    font-weight: 700;
    font-size: 20px;
  }
  .map {
    display: flex;
    justify-content: flex-end;
    .left {
      width: 500px;
      height: 500px;
      margin: auto;
      img {
        object-fit: cover;
        width: 100%;
        height: 100%;
      }
    }
    .right {
      display: flex;
      flex-direction: column;
      margin: 0 auto;
      width: 300px;
      .up {
        text-align: center;
        .showPhoto {
          display: flex;
          flex-flow: wrap;
          justify-content: space-between;
          .little {
            display: inline-block;
            img {
              object-fit: cover;
              padding: 10px;
              vertical-align: middle;
              width: 120px;
              height: 120px;
              cursor: pointer;
            }
          }
        }
        .price {
          padding: 20px 0;
          span {
            font-size: 20px;
            line-height: 20px;
            font-weight: 700;
          }
        }
      }
    }
  }
  .content {
    padding: 30px;
    text-indent: 2em;
    font-size: 20px;
    line-height: 1.5;
  }
}
</style>